Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension_host: Improve Wasmtime timeslicing behavior for extensions #24986

Closed

Conversation

benbrandt
Copy link

Addresses the discussion that goes into depth on why this is important when enabling async support with Wasmtime.

The tldr; is, async mode puts component execution within a Future::poll call, which if the component code is malicious or just expensive, can then block a given async thread.

With this change it should provide an upper bound on how long a given extension can run before yielding back and allowing another task to execute.

This could be extended to also provide an upper bound to how long you would want a given call to take at all, as this implementation will still let it happily take forever, it just has to let other extensions have a turn.

Happy to discuss more, and also make any changes in case I missed something here. Or close if this change isn't desired for any reason.

Release Notes:

  • Improved wasmtime timeslicing behavior for extensions

Addresses the [discussion](zed-industries#24515) that goes into depth on why this is important when enabling async support with Wasmtime.

The tldr; is, async mode puts component execution within a `Future::poll` call, which if the component code is malicious or just expensive, can then block a given async thread.

With this change it should provide an upper bound on how long a given extension can run before yielding back and allowing another task to execute.

This could be extended to also provide an upper bound to how long you would want a given call to take at all, as this implementation will still let it happily take forever, it just has to let other extensions have a turn.

Happy to discuss more, and also make any changes in case I missed something here. Or close if this change isn't desired for any reason.

Release Notes:

- Improved wasmtime timeslicing behavior for extensions

This comment was marked as resolved.

@benbrandt

This comment was marked as resolved.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 16, 2025

This comment was marked as resolved.

@maxdeviant maxdeviant changed the title Improve wasmtime timeslicing behavior for extensions extension_host: Improve Wasmtime timeslicing behavior for extensions Feb 16, 2025
Comment on lines +407 to +408
store.set_epoch_deadline(1);
store.epoch_deadline_async_yield_and_update(1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there are a few other options:

  1. Change either the epoch interval or deadline to just put an upper bound on component execution (this is what Spin does)
  2. Do the callback version where you can decide if you want to yield or trap

No matter which way, since I believe you all have a timeout further up, the future will eventually get dropped, but any variation should still help.

@benbrandt
Copy link
Author

I will also say, as I did in the discussion, I'm happy to add some more test cases around this. I just wanted to put the code in a PR in case that made it easier to discuss first.

@benbrandt
Copy link
Author

Closing this for now. We can continue discussion on the discussion as it probably needs to be ironed out which direction to push this before this would be mergeable anyway.

@benbrandt benbrandt closed this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant